<?php
/**
 * Created by PhpStorm.
 * User: yaoihu
 * Date: 2019/6/13
 * Time: 7:03
 */

namespace Frontend\Http\Requests;


use Illuminate\Foundation\Http\FormRequest;

class RetrieveRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        if ($this->isMethod('post')){
            return [
                'phone'=>'required|mobile',
                'pwd'=>'required|pwd_rule',
                're_pwd'=>'required|same:pwd',
                'phone_code'=>'bail|required|numeric|digits:6',
            ];
        }
        return [];
    }

    public function attributes()
    {
        return [
            'phone'=>'手机号',
            'pwd'=>'密码',
            're_pwd'=>'确密码',
            'phone_code'=>'手机验证码',
        ];
    }

    public function messages()
    {
        return [
            'required'=>':attribute不能为空',
            'mobile'=>':attribute格式不正确',
            'unique'=>':attribute不能重复',
            'alpha_start'=>':attribute只能已字母开头，只包含字母和数字',
            'alpha_num'=>':attribute只能包含字母和数字',
            'pwd_rule'=>':attribute不符合规则',
            'numeric'=>':attribute只能是数字',
            'same'=>':attribute必须和:field相同',
            'digits'=>':attribute只能为:digits位的数字',
        ];
    }
}